package com.ruoyi.eam.controller;

import java.util.List;
import java.io.IOException;
import java.util.Random;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eam.doman.EamReturnH;
import com.ruoyi.eam.service.IEamReturnHService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资产退还Controller
 * 
 * @author ruoyi
 * @date 2024-07-09
 */
@RestController
@RequestMapping("/returnH")
public class EamReturnHController extends BaseController
{
    @Autowired
    private IEamReturnHService eamReturnHService;

    /**
     * 查询资产退还列表
     */
    //@RequiresPermissions("return:h:list")
    @GetMapping("/list")
    public TableDataInfo list(EamReturnH eamReturnH)
    {
        startPage();
        List<EamReturnH> list = eamReturnHService.selectEamReturnHList(eamReturnH);
        return getDataTable(list);
    }

    /**
     * 导出资产退还列表
     */
    //@RequiresPermissions("return:h:export")
    @Log(title = "资产退还", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EamReturnH eamReturnH)
    {
        List<EamReturnH> list = eamReturnHService.selectEamReturnHList(eamReturnH);
        ExcelUtil<EamReturnH> util = new ExcelUtil<EamReturnH>(EamReturnH.class);
        util.exportExcel(response, list, "资产退还数据");
    }

    /**
     * 获取资产退还详细信息
     */
    //@RequiresPermissions("return:h:query")
    @GetMapping(value = "/{returnId}")
    public AjaxResult getInfo(@PathVariable("returnId") Long returnId)
    {
        return success(eamReturnHService.selectEamReturnHByReturnId(returnId));
    }

    /**
     * 新增资产退还
     */
    //@RequiresPermissions("return:h:add")
    @Log(title = "资产退还", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EamReturnH eamReturnH)
    {
        return toAjax(eamReturnHService.insertEamReturnH(eamReturnH));
    }

    /**
     * 修改资产退还
     */
    //@RequiresPermissions("return:h:edit")
    @Log(title = "资产退还", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EamReturnH eamReturnH)
    {
        return toAjax(eamReturnHService.updateEamReturnH(eamReturnH));
    }

    /**
     * 删除资产退还
     */
    //@RequiresPermissions("return:h:remove")
    @Log(title = "资产退还", businessType = BusinessType.DELETE)
	@DeleteMapping("/{returnIds}")
    public AjaxResult remove(@PathVariable Long[] returnIds)
    {
        return toAjax(eamReturnHService.deleteEamReturnHByReturnIds(returnIds));
    }

    @GetMapping("/getCode")
    public  AjaxResult generateEncodedString() {
        // 获取当前时间戳
        Random random = new Random();
        // 生成一个16位的随机整数
        long randomNumber = (long) (random.nextDouble() * 9000000000000000L) + 1000000000000000L;
                // 返回编码后的字符串
        return AjaxResult.success("THD"+randomNumber);
    }
}
